<!-- 订单备料作业:蹇泽阳 -->
<template>
  <div class="app-container">
    <Find :OriginalFilter="{ static: true }" @clickNumber1="clickNumber1" :formList="formList" @findClicked="findClicked" />

    <div class="flex mt10" style="width: 100%; background-color: white">
      <el-card shadow="never" :body-style="{ padding: '5px 10px 5px' }">
        <div slot="header" class="f16">
          <span style="font-weight: 600; margin-right: 5px">待备料的订单资料</span>
        </div>
        <div class="flex">
          <el-button type="primary" @click="OrderMasking" class="primaryBth mr5">订单屏蔽</el-button>
          <el-button type="primary" @click="dialogTableVisible = true" class="primaryBth">屏蔽取消</el-button>
        </div>
        <Table
          :tableData="tableData"
          :tableHeader="tableHeader"
          selection
          :isLoading="isLoading"
          @currentRow="currentRow"
          @selectList="selectList1"
          :outTableHeight="150"
        />
      </el-card>

      <el-card shadow="never" :body-style="{ padding: '5px 10px 5px' }" class="main">
        <div class="flex">
          <span style="font-weight: 600">订单材料明细</span>
          <AddOne :tableHeader="tableHeader2" :tableData="tableData2" @Save="Save2" @AddHandle="AddHandle2" />
          <el-button type="primary" size="default" @click="removeOne" style="background-color: red">删除打勾数据</el-button>
        </div>
        <JTable
          :tableData="tableData2"
          :tableHeader="tableHeader2"
          selection
          @selectList="selectList2"
          :getTableList="currentRow"
          @currentRow="currentRow2"
          @inputChange="inputChange2"
          @selectValChange="selectValChange2"
        />
      </el-card>
    </div>

    <el-card shadow="never" :body-style="{ padding: '5px' }">
      <PageModule :PageData="{ total }" @pageSizeChange="handleSizeChange" @pageChange="handleCurrentChange" />
    </el-card>

    <!-- 订单屏蔽 -->
    <el-drawer v-model="dialogTableVisible" :direction="'rtl'" size="small" :with-header="false">
      <el-card shadow="never" :body-style="{ padding: '11px 20px' }">
        <div slot="header" class="f16">
          <span style="font-weight: 600">屏蔽的指令</span>
        </div>
        <div class="flex mt10">
          <div class="flex" style="flex-direction: column">
            <Table :tableHeader="tableHeader3" :tableData="tableData3" class="mr55" @currentRow="currentRow3" />
            <PageModule
              :PageData="{ total: total2, pageSizeShow: true, buttonS: true }"
              :layout="'prev, pager'"
              @pageSizeChange="handleSizeChange2"
              @pageChange="handleCurrentChange2"
              style="margin-left: -80px"
            />
            <div class="flex mt30" style="justify-content: space-around">
              <el-button type="primary" size="default" @click="back">返回</el-button>
              <el-button type="primary" size="default" @click="cancelShield">取消屏蔽</el-button>
            </div>
          </div>

          <div class="mt30 flex" style="flex-direction: column; align-items: center">
            <div class="mb36">
              <span class="mr10">指令</span>
              <el-input v-model="searchLotNo" placeholder="" clearable @change="" class="w-50 el-input__inner primaryBth"></el-input>
            </div>
            <el-button type="primary" size="default" @click="getTableList2" class="primaryBth" style="width: 64px">查询</el-button>
          </div>
        </div>
      </el-card>
    </el-drawer>

    <!-- 打勾指令材料复制到指令 -->
    <el-drawer v-model="dialogTableVisible2" :direction="'ttb'" size="small" :with-header="false">
      <Find :OriginalFilter="{ static: true }" :formList="formList2" @findClicked="findClicked2" />
      <el-card shadow="never" :body-style="{ padding: '11px 20px' }">
        <div slot="header" class="f16">
          <span style="font-weight: 600">选择订单</span>
        </div>
        <Table :tableHeader="tableHeader4" :tableData="tableData4" class="mr55" selection @selectList="selectList3" />
        <PageModule :PageData="{ total: total3, buttonS: true }" @pageSizeChange="handleSizeChange3" @pageChange="handleCurrentChange3" />
      </el-card>
    </el-drawer>
  </div>
</template>
<script lang="ts">
import { selectList, selectSomeList } from '@/plugins/mixin'
import router from '@/router'
import LoginWork from '@/utils/LoginWork'
import service from '@/utils/request'
import { ElMessage, ElMessageBox } from 'element-plus'
import { debounce } from 'lodash'
import { defineComponent, onBeforeUnmount, onMounted, onUnmounted, ref, watch } from 'vue'
import JMessage from '@/utils/JMessage'
export default defineComponent({
  name: 'OrderMaterialPreparationOperation'
})
</script>
<script lang="ts" setup>
import { i18n, Jzhcn } from '@/i18n'
const formList = ref([
  {
    type: 'input',
    inputPlaceholder: '请输入指令号',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入纸板号',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入材料名称',
    inputValue: ''
  },
  {
    type: 'radio1',
    checkboxLabel: '未检核',
    label: '1'
  },
  {
    type: 'radio1',
    checkboxLabel: '已检核',
    label: '2'
  },
  {
    type: 'radio1',
    checkboxLabel: '未完成',
    label: '3'
  },
  {
    type: 'radio1',
    checkboxLabel: '已完成',
    label: '4'
  },
  {
    type: 'radio1',
    checkboxLabel: '全部',
    label: '0'
  },
  // {
  //   type: 'button',
  //   checkboxLabel: '分类辅助生成',
  // },
  {
    type: 'button',
    checkboxLabel: '打勾记录检核'
  },
  {
    type: 'button',
    checkboxLabel: '打勾记录取消检核'
  },
  {
    type: 'button',
    checkboxLabel: '转采购作业 >>'
  },
  {
    type: 'button',
    checkboxLabel: '分类辅助生成'
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  },
  {
    type: 'input',
    inputPlaceholder: '请输入品牌',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入工厂货号',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入材料颜色',
    inputValue: ''
  },

  {
    type: 'button',
    checkboxLabel: '置空物料编码'
  },
  {
    type: 'button',
    checkboxLabel: '生成物料编码'
  },
  {
    type: 'button',
    checkboxLabel: '打勾指令材料复制到指令'
  },
  {
    type: 'button',
    checkboxLabel: '勾选指令刷新材料单'
  }
])
const tableHeader = ref([
  {
    backgroundColor: true,
    label: '指令号',
    prop: 'lotNo',
    width: 150
  },
  {
    label: '工厂货号',
    prop: 'custStyle'
  },
  {
    label: '品牌',
    prop: 'brand'
  },
  {
    label: '纸板号',
    prop: 'shoeName'
  },
  {
    label: '颜色',
    prop: 'color'
  },
  {
    label: '号码',
    prop: 'sizeNo',
    width: 50
  },
  {
    label: '数量',
    prop: 'orderQty'
  },
  {
    label: '订单状态',
    prop: 'mallStatus'
  }
])

// 表一模块
// 置空按钮
const findClicked = async (content: string) => {
  if (content === '置空') {
    formList.value.forEach((item: any) => {
      item.inputValue = ''
      item.selectValue = ''
      item.dateValue = ''
    })
  }
  if (content === '打勾指令材料复制到指令') {
    if (selectedCopyList.length === 0) {
      JMessage.warning('请打勾订单材料明细')
      return
    }
    dialogTableVisible2.value = true
  }
  if (content === '打勾记录检核') {
    if (selectedList.value.length === 0) {
      JMessage.warning('请打勾待备料的订单资料')
      return
    }
    let res = await LoginWork.post<any, any>('/pcOrder/operate/setMtlNoCopyInLotNo', {
      check: 0,
      choose: 1, //	0:代表当前指令材料复制到指令 1：代表使用检核接口	string	body	true
      lotNos: selectedList.value //	指令号	array	body	true
    })
    if (res.code === 200) {
      JMessage.success(res.message)
    } else {
      JMessage.warning(res.message)
    }
    getTableList()
  }
  if (content === '打勾记录取消检核') {
    if (selectedList.value.length === 0) {
      JMessage.warning('请打勾待备料的订单资料')
      return
    }
    let res = await LoginWork.post<any, any>('/pcOrder/operate/setMtlNoCopyInLotNo', {
      check: 1,
      choose: 1, //	0:代表当前指令材料复制到指令 1：代表使用检核接口	string	body	true
      lotNos: selectedList.value //	指令号	array	body	true
    })
    if (res.code === 200) {
      JMessage.success(res.message)
    } else {
      JMessage.warning(res.message)
    }
    getTableList()
  }
  if (content === '转采购作业 >>') {
    router.push({
      path: '/Develop/RYDevelopment/MaterialOrdering'
    })
  }
  if (content === '置空物料编码') {
    if (selectedCopyList.length === 0) {
      JMessage.warning('请打勾订单材料明细')
      return
    }
    let res = await LoginWork.post<any, any>('/pcOrder/operate/setMtlNoInPickingOperate', {
      code: 0,
      list: selectedCopyList,
      lotNos: [currentLotNo.value] //	指令号	array	body	true
    })
    if (res.code === 200) {
      JMessage.success(res.message)
    } else {
      JMessage.error(res.message)
    }
    currentRow(currentTableRow.value)
  }
  if (content === '生成物料编码') {
    if (selectedCopyList.length === 0) {
      JMessage.warning('请打勾订单材料明细')
      return
    }
    let res = await LoginWork.post<any, any>('/pcOrder/operate/setMtlNoInPickingOperate', {
      code: 1,
      list: selectedCopyList,
      lotNos: [currentLotNo.value] //	指令号	array	body	true
    })
    if (res.code === 200) {
      JMessage.success(res.message)
    } else {
      JMessage.error(res.message)
    }
    currentRow(currentTableRow.value)
  }
  if (content === '分类辅助生成') {
    let res = await LoginWork.post<any, any>('/pcOrder/operate/setTypeNameInPickingOperate', {
      lotNo: currentTableRow.value.lotNo,
      pickingOperateDetailRepList: tableData2.value
    })
    if (res.code === 200) {
      JMessage.success(res.message)
      currentRow(currentTableRow.value)
    } else {
      JMessage.error(res.message)
    }
  }
  if (content === '勾选指令刷新材料单') {
    if (selectedList.value.length === 0) {
      JMessage.warning('请打勾待备料的订单资料')
      return
    }
    let res = await LoginWork.post<any, any>('/pcOrder/operate/refreshOrderMaterialDaI2', selectedList.value)
    if (res.code === 200) {
      JMessage.success(res.message)
      getTableList()
    } else {
      JMessage.error(res.message)
    }
  }
}
const tableData = ref([])
const isLoading = ref(true)
// 分页器
const currentPage = ref(1)
const pageSize = ref(40)
const total = ref(0)
const handleSizeChange = (val: number) => {
  pageSize.value = val
  getTableList()
}
const handleCurrentChange = (val: number) => {
  currentPage.value = val
  getTableList()
}
// 获取表数据
const getTableList = debounce(async () => {
  isLoading.value = true
  let tableDataList = await service.post<any, any>('/pcOrder/operate/getPickingOperate', {
    brand: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入品牌'
    )?.inputValue,
    custStyle: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入工厂货号'
    )?.inputValue,
    lotNo: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入指令号'
    )?.inputValue,
    mtlCheck: radio.value,
    mtlColor: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入材料颜色'
    )?.inputValue,
    mtlName: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入材料名称'
    )?.inputValue,
    shoeName: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入纸板号'
    )?.inputValue,
    pageNum: currentPage.value,
    pageSize: pageSize.value
  })
  isLoading.value = false
  tableData.value = tableDataList.list.map((item: any) => {
    item.backgroundColor === 'Y' ? (item.backgroundColor = '#80c080') : (item.backgroundColor = 'initial')
    return item
  })
  total.value = tableDataList.total
  currentRow()
}, 500)
onMounted(() => {
  getTableList()
})
watch(
  () =>
    formList.value.map((item: any) => {
      item.selectValue, item.inputValue, item.dateValue, item.checked
    }),
  () => {
    getTableList()
  }
)

const tableHeader2 = ref<any>([
  {
    type: 'select',
    label: '分类名称',
    prop: 'typeName',
    options: []
  },
  {
    backgroundColor: true,
    label: '物料编码',
    prop: 'mtlNo',
    width: 90
  },
  {
    backgroundColor2: true,
    label: '材料颜色',
    prop: 'mtlColor'
  },
  {
    start: true,
    label: '材料名称',
    prop: 'mtlName',
    width: 450,
    options: []
  },
  {
    type: 'select',
    label: '规格',
    prop: 'mtlSpec',
    options: []
  },
  {
    type: 'select',
    label: '单位',
    prop: 'mtlUnit',
    options: []
  },
  {
    label: '用量',
    prop: 'usage'
  },
  {
    label: '备注',
    prop: 'remark'
  }
])
const currentLotNo = ref('')
// 点击表给另一张表传数据
const currentTableRow = ref()
const currentRow = async (row: any = tableData.value[0] ? tableData.value[0] : {}) => {
  currentTableRow.value = row
  let { lotNo }: any = row
  currentLotNo.value = lotNo
  tableData2.value = await service.post<any, any>(`/pcOrder/operate/getPickingOperateDetail?lotNo=${currentTableRow.value.lotNo}`)
  tableData2.value = tableData2.value.list.map((item: any) => {
    item.backgroundColor1 === 'ok' ? (item.backgroundColor = '#80c080') : (item.backgroundColor = '#ffffff') //第一列修改颜色
    item.backgroundColor2 === 'ok' ? (item.backgroundColor2 = '#ffc0ff') : (item.backgroundColor2 = '#ffffff') //第二列修改颜色
    item.backgroundColor3 === 'ok' ? (item.backgroundColor99 = '#ffc0ff') : (item.backgroundColor99 = '#ffffff') //第三列修改颜色
    if (item.mtlNo === null || item.mtlNo === '') {
      item.disable = false // 当mtlNo这一列为空时，加了change的行都可以修改。tableHeader的change等于true时，这一列不准修改
      item.change = 'Y'
    } else {
      // tableHeader2.value.find((item: any) => item.label === '分类名称').disable = true // 当mtlNo这一列不为空时，分类名称这一列对应行不可修改
      tableHeader2.value.find((item: any) => item.label === '材料颜色').disable = true // 当mtlNo这一列不为空时，材料颜色这一列对应行不可修改
      tableHeader2.value.find((item: any) => item.label === '材料名称').disable = true // 当mtlNo这一列不为空时，材料名称这一列对应行不可修改
      tableHeader2.value.find((item: any) => item.label === '规格').disable = true // 当mtlNo这一列不为空时，材料名称这一列对应行不可修改
      tableHeader2.value.find((item: any) => item.label === '单位').disable = true // 当mtlNo这一列不为空时，材料名称这一列对应行不可修改
      item.disable = true
    }
    item.disableConfirm = true
    if (!item.typeName) item.addAndUpdate = true
    // if (item.mtlNo) {
    //   item.addAndUpdate = false
    // } else item.addAndUpdate = true

    // item.mtlName = {
    //   selectValue: item.mtlName,
    //   PageModule: true,
    //   total: 0,
    //   handleSizeChange: (val: any) => {
    //     pageSize4.value = val;
    //     getSelectList5(item);
    //   },
    //   handleCurrentChange: (val: any) => {
    //     currentPage4.value = val;
    //     getSelectList5(item);
    //   },
    //   options: [],
    // };
    // item.mtlSpec = {
    //   selectValue: item.mtlSpec,
    //   options: [],
    // };
    // item.typeName = {
    //   selectValue: item.typeName,
    //   options: [],
    // };
    // item.mtlUnit = {
    //   selectValue: item.mtlUnit,
    //   options: [],
    // };
    // // 修改表格中下拉框数据
    // // 修改材料名称数据
    // if (!item.mtlNo) {
    //   // 如果这一行没有物料编码
    //   getSelectList4(item);
    //   getSelectList5(item);
    //   getSelectList6(item);
    // }
    item.change = 'Y'
    return item
  })
}

// 订单屏蔽
const selectedList = ref([])
const selectList1 = (selectList: any) => {
  selectedList.value = selectList.map((item: any) => {
    return item.lotNo
  })
}
const OrderMasking = async () => {
  if (selectedList.value.length === 0) {
    JMessage.warning('请勾选待备料的订单资料')
    return
  }
  let res = await LoginWork.post<any, any>('/pcOrder/operate/pcOrderShielding', {
    lots: selectedList.value,
    shield: 0
  })
  JMessage.success(res.message)
  getTableList()
}

// 取消屏蔽
const dialogTableVisible = ref(false)
const searchLotNo = ref('')
const tableHeader3 = ref([
  {
    label: '指令',
    prop: 'lotNo',
    width: 250
  }
])
const tableData3 = ref([])
// 分页器
const currentPage2 = ref(1)
const pageSize2 = ref(40)
const total2 = ref(0)
const handleSizeChange2 = (val: number) => {
  pageSize2.value = val
  getTableList2()
}
const handleCurrentChange2 = (val: number) => {
  currentPage2.value = val
  getTableList2()
}
// 获取表数据
const getTableList2 = debounce(async () => {
  let tableDataList = await service.post<any, any>(
    `/pcOrder/operate/pcOrderShieldingList?lotNo=${searchLotNo.value}&pageNum=${currentPage2.value}&pageSize=${pageSize2.value}`
  )
  tableData3.value = tableDataList.list.map((item: any) => {
    return { lotNo: item }
  })
  total2.value = tableDataList.total
}, 500)
onMounted(() => {
  getTableList2()
})
const tableData2 = ref<any>([])
const radio = ref(0)
const clickNumber1 = (row: number) => {
  radio.value = row
  getTableList()
}

const currentLotNoRow = ref('')
const currentRow3 = async (row: any) => {
  currentLotNoRow.value = row.lotNo
}
const cancelShield = async () => {
  let res = await LoginWork.post<any, any>(`/pcOrder/operate/pcOrderShielding`, {
    lots: [currentLotNoRow.value],
    shield: 1
  })
  JMessage.success(res.message)
  getTableList2()
}
// 返回按钮
const back = () => {
  getTableList()
  dialogTableVisible.value = false
}

// 打勾指令材料复制到指令
let selectedCopyList = [] as any
const selectedLotNoCopyList = ref([])
const dialogTableVisible2 = ref(false)
const formList2 = ref([
  {
    type: 'input',
    inputPlaceholder: '请输入指令',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入工厂货号',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '品牌',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '返回'
  },
  {
    type: 'button',
    checkboxLabel: '复制到打勾指令'
  }
])
const tableHeader4 = ref([
  {
    label: '指令号',
    prop: 'lotNo'
  },
  {
    label: '品牌',
    prop: 'brand'
  },
  {
    label: '纸板号',
    prop: 'shoeName'
  },
  {
    label: '工厂货号',
    prop: 'custStyle'
  },
  {
    label: '颜色',
    prop: 'color'
  },
  {
    label: '数量',
    prop: 'orderQty'
  }
])
const tableData4 = ref([])
// 置空按钮
const findClicked2 = async (content: string) => {
  if (content === '置空') {
    formList2.value.forEach((item: any) => {
      item.inputValue = ''
      item.selectValue = ''
      item.dateValue = ''
    })
  }
  if (content === '返回') {
    dialogTableVisible2.value = false
  }
  if (content === '复制到打勾指令') {
    if (selectedLotNoCopyList.value.length === 0) {
      JMessage.warning('请打勾选择订单')
      return
    }
    let res = await LoginWork.post<any, any>('/pcOrder/operate/setMtlNoCopyInLotNo', {
      choose: 0, //	0:代表当前指令材料复制到指令 1：代表使用检核接口	string	body	true
      list: selectedCopyList, //		array	body	true
      lotNos: selectedLotNoCopyList.value.map((item: any) => item.lotNo) //	指令号	array	body	true
    })
    if (res.code === 200) {
      JMessage.success(res.message)
    } else {
      JMessage.warning(res.message)
    }
    dialogTableVisible2.value = false
    ;(
      formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入指令号'
      ) as any
    ).inputValue = selectedLotNoCopyList.value.map((item: any) => item.lotNo)[0]
    currentTableRow.value = tableData.value[0]
    currentRow()
  }
}
// 分页器
const currentPage3 = ref(1)
const pageSize3 = ref(40)
const total3 = ref(0)
const handleSizeChange3 = (val: number) => {
  pageSize3.value = val
  getTableList3()
}
const handleCurrentChange3 = (val: number) => {
  currentPage3.value = val
  getTableList3()
}
const selectedLists2 = ref([]) as any
const selectList2 = (selected: any) => {
  selectedLists2.value = selected
  selectedCopyList = JSON.parse(JSON.stringify(selected))
  selectedCopyList.forEach((copyRow: any) => {
    for (const key in copyRow) {
      if (copyRow[key] && (copyRow[key].selectValue || copyRow[key].selectValue === null)) {
        copyRow[key] = copyRow[key].selectValue
      }
    }
  })
}
// 获取打勾指令复制到指令数据
const getTableList3 = debounce(async () => {
  let tableDataList = await service.post<any, any>('/pcOrder/operate/getPickingOperate', {
    brand: formList2.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '品牌')
      ?.selectValue,
    custStyle: formList2.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入工厂货号'
    )?.inputValue,
    lotNo: formList2.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入指令'
    )?.inputValue,
    pageNum: currentPage.value,
    pageSize: pageSize.value
  })
  tableData4.value = tableDataList.list
  total3.value = tableDataList.total
}, 500)
const selectList3 = (selected: any) => {
  selectedLotNoCopyList.value = selected
}
onMounted(() => {
  getTableList3()
})
watch(formList2.value, () => {
  getTableList3()
})

const getSelectList = async () => {
  await selectList(formList2, () => service.get('/back/order/allOrderCondition'))
}
onMounted(() => {
  getSelectList()
})

// 获取表格中下拉框数据
// 获取分类名称下拉框数据
const getSelectList4 = async () => {
  const res = await service.get<any, any>('/back/getMtlType3')
  res.forEach((Vendor: any) => {
    tableHeader2.value
      .find((item: any) => item.label === '分类名称')
      .options.push({
        label: `${Vendor.typeName}`,
        value: `${Vendor.typeNo}  ${Vendor.typeName}`,
        LeftLabel: `${Vendor.typeNo}`,
        RightLabel: `${Vendor.typeName}`
      })
  })
}
// 获取材料名称下拉框数据
const getSelectList5 = async () => {
  const res = await service.get<any, any>('/back/getMtlName3', {
    params: {
      mtlName: '',
      mtlNo: '',
      pageNum: '0',
      pageSize: '99999'
    }
  })
  res.list.map((Vendor: any) => {
    tableHeader2.value
      .find((item: any) => item.label === '材料名称')
      .options.push({
        label: `${Vendor.mtlNo}  ${Vendor.mtlName}  ${Vendor.mtlColor}  ${Vendor.mtlUnit}  ${Vendor.mtlSpec}`,
        value: `${Vendor.mtlNo}  ${Vendor.mtlName}  ${Vendor.mtlColor}  ${Vendor.mtlUnit}  ${Vendor.mtlSpec}`,
        LeftLabel: `${Vendor.mtlColor}  ${Vendor.mtlName}`,
        RightLabel: `${Vendor.mtlUnit}  ${Vendor.mtlSpec}  ${Vendor.mtlNo}`
      })
  })
}
// 获取规格和单位下拉框数据
const getSelectList6 = async () => {
  const { specs, units } = await service.get<any, any>('/back/getMtlUS1')
  specs.map((Vendor: any) => {
    tableHeader2.value
      .find((item: any) => item.label === '规格')
      .options.push({
        label: Vendor,
        value: Vendor
      })
  })
  units.map((Vendor: any) => {
    tableHeader2.value
      .find((item: any) => item.label === '单位')
      .options.push({
        label: Vendor,
        value: Vendor
      })
  })
}
onMounted(() => {
  getSelectList4()
  // getSelectList5()
  getSelectList6()
})

const Save2 = async (arr: any, deleteArr: any) => {
  const res = (await LoginWork.post(`/pcOrder/operate/pcOrderMaterialDaI1`, {
    choose: 2,
    lotNo: currentTableRow.value.lotNo,
    rep: arr.filter((item: any) => item.mtlName)
  })) as any
  // 判断请求是否成功
  if (res.code === 200) {
    deleteArr()
    JMessage.success(res.message)
    currentRow(currentTableRow.value)
  } else {
    JMessage.error(res.message)
  }
}
const AddHandle2 = (obj2: any, arr: any) => {
  for (let index = 0; index < 5; index++) {
    const obj = {} as any
    for (const key in tableData2.value) {
      obj[tableData2.value[key].prop] = ''
    }
    obj.addAndUpdate = true
    obj.disableConfirm = true
    tableData2.value.unshift(obj)
    arr.push(obj)
  }
}

// 删除
const removeOne = async () => {
  if (selectedLists2.value.length === 0) {
    JMessage.error('请选择要删除的行')
    return
  }
  // 向服务器发送请求，更新外派单信息
  const res = (await LoginWork.post(`/pcOrder/operate/pcOrderMaterialDaI1`, {
    choose: 1,
    lotNo: currentTableRow.value.lotNo,
    rep: selectedLists2.value
  })) as any
  // 判断请求是否成功
  if (res.code === 200) {
    JMessage.success(res.message)
  } else {
    JMessage.error(res.message)
  }
  // 重新获取表格数据
  currentRow(currentTableRow.value)
}

// 修改
let currentLotNoRow2 = ref({})
const currentTableRow2 = ref({})
const currentRow2 = (row: any) => {
  currentTableRow2.value = row
  const copyRow = JSON.parse(JSON.stringify(row))
  for (const key in copyRow) {
    if (copyRow[key] && copyRow[key].selectValue) {
      copyRow[key] = copyRow[key].selectValue
    }
  }
  currentLotNoRow2.value = { ...copyRow, lotNo: currentLotNo.value }
}

const inputChange2 = async (row: any) => {
  if (row.id) {
    console.log('修改')
    const res = (await LoginWork.post(`/pcOrder/operate/updatePickingOperate1`, {
      ...row,
      lotNo: currentTableRow.value.lotNo
    })) as any
    // 判断请求是否成功
    if (res.code === 200) {
      JMessage.success(res.message)
    } else {
      JMessage.error(res.message)
      currentRow(currentTableRow.value)
    }
  }
}
const selectValChange2 = async (row: any) => {
  console.log(row)

  if (row.id) {
    console.log('修改')
    const res = (await LoginWork.post(`/pcOrder/operate/updatePickingOperate1`, {
      ...row,
      lotNo: currentTableRow.value.lotNo,
      mtlTypeNo: row.typeName.split('  ')[0] || '',
      typeName: row.typeName.split('  ')[1] || ''
    })) as any
    // 判断请求是否成功
    if (res.code === 200) {
      JMessage.success(res.message)
    } else {
      JMessage.error(res.message)
      currentRow(currentTableRow.value)
    }
  }
}
onBeforeUnmount(() => {
  console.log(111111111111)
})
</script>

<style lang="less" scoped></style>
